package com.leetcode.题库;

/**
 * @author 覃国强
 * @date 2022-03-16 19:48
 */
public class 题库_0167_两数之和II_输入有序数组 {

  static
  class Solution {
    public int[] twoSum(int[] numbers, int target) {
      if (numbers == null || numbers.length == 0) {
        return new int[0];
      }
      int index1 = 0;
      int index2 = numbers.length - 1;
      while (index1 < index2) {
        int sum = numbers[index1] + numbers[index2];
        if (sum == target) {
          return new int[] {index1 + 1, index2 + 1};
        }
        if (sum < target) {
          ++index1;
        } else {
          --index2;
        }
      }
      return new int[0];
    }
  }

}
